<?php
namespace app\[MODULE]\controller;
use think\facade\Db;
use app\[MODULE]\model\[UTABLE] as [UTABLE]Model;

class [CONTROLLER] extends Base{
    

    /**
     * 首页
     */
    public function index(){
        if(IS_POST) {
            $search  = request()->param();
            $where = [];
            [SEARCH]
            $db   = [UTABLE]Model::where($where)->order('id desc');
            $list = $db->page($search['page'],$search['limit'])->select();
            [IMGTEMP]
            admin_response(0, 'success', $list, $db->count());
        }
        if(IS_EXCEL) {
            $db = [UTABLE]Model::where($where)->order('id asc');
            big_array_to_csv($db, '数据导出', []);
        }
        return $this->render_table([
           [ITEM]
            ],false);

    }



        /**
     * 添加
     * @return void
     * @author 
     * @date 
     */
    public function add(){
        if(request()->isPost()) {
           $data = request()->post();
           if([UTABLE]Model::create($data)) json_response(1,'操作成功');
           json_response(0,'操作失败');
        }else{
           return $this->render_form([
               [FORMITEM] 
           ]);
        }
    }



    /**
     * 编辑
     * @return void
     * @author 
     * @date 
     */
    public function edit(){
        $id = \param_check('id');
        if(request()->isPost()) {
           $data = request()->post();
           if([UTABLE]Model::update($data,['id'=>$id])) json_response(1,'操作成功');
           json_response(0,'操作失败');
        }else{
            $data = [UTABLE]Model::get($id);
           return $this->render_form([
                [FORMITEM]
           ],$data);
        }
    }





        /**
     * 删除
     * @return void
     * @author Sam
     * @date 2021-07-01
     */
    public function del(){
        $id = param_check('id');
        if(!$[UTABLE]Model = [UTABLE]Model::get($id)) json_response(0,'不存在');
        if($[UTABLE]Model->delete()) json_response(1,'操作成功');
        json_response(0,'操作失败');
    }

}